Skip to content

ignition(preparation): skip unreferenced epilogue candidates in relocate_inductor - #642

Open
jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:pr/relocate-inductor-epilogue-candidates
Open

jcartu wants to merge 1 commit into
NVIDIA:mainfrom
jcartu:pr/relocate-inductor-epilogue-candidates

Conversation

@jcartu

@jcartu jcartu commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Tensor-parallel preparation aborts with KeyError on relocating ranks when a compiled forward's Triton bundle holds a static autotuner that the generated Python module never defines. During multi-rank preparation (ForwardCache._prepare_ranks in ignition/preparation/aot.py), self._load deserializes compiled forwards through aot._load_inductor with frozen false (the artifact's _tuning_frozen before InductorSelections.freeze), which invokes relocate_inductor (ignition/preparation/device_binding.py) before InductorSelections.freeze prunes bundle.static_autotuners. On the compiler rank (target == original) with freeze_tuning=False, relocate_inductor returns early without inspecting static_autotuners, and InductorSelections.register (ignition/preparation/inductor_tuning.py) ignores unreferenced static_autotuners entries left behind by PyTorch Inductor epilogue-fusion benchmarking (entry.kernel_name absent from the generated Python module). On peer tensor-parallel ranks (target != original) during the unfrozen load, relocate_inductor previously assigned graph.source_code, graph.cache_key, and graph.device_idxs before its loop and indexed kernel_keys[entry_kernel.cache_key] across every entry in bundle.static_autotuners. Because _device_source populates kernel_keys only from async_compile.triton calls present in graph.source_code, on an unfrozen peer load a bundled candidate whose cache key was absent from kernel_keys raised KeyError. Compiler-rank registration accepted the candidate in the TP4 reproduction, but its substring check could reject unused candidates with prefix-colliding names. When freeze_tuning=True (ForwardCache._load sets it from the triton.autotune_at_compile_time option), _freeze_tuning_winners also ran before checking bindings on both compiler and peer ranks, so an unresolved unreferenced candidate or referenced unbound kernel could fail winner freezing before missing bindings were diagnosed. In addition, InductorSelections.register previously mutated self.instances and called _install before checking unbound entries, collapsed duplicate unbound cache_key snapshots before checking names, and checked entry.kernel_name in graph.source_code by substring rather than exact identifier, which false-matches a prefix candidate such as triton_tem_fused_1 when triton_tem_fused_10 is bound (reproduced in CPU unit tests).

Dropping unreferenced static_autotuners entries during relocation and winner freezing is sound because any entry whose cache key has no async_compile.triton definition cannot be launched by the generated module, every launch in generated Inductor code names its kernel via a module-global identifier or async_compile.triton call string, and InductorSelections.freeze discards unreferenced entries on every rank anyway.

What Changed

  • ignition/preparation/device_binding.py & ignition/preparation/inductor_tuning.py: Adds _referenced_kernel_names(source) (collecting AST Name identifiers and async_compile.triton string kernel names), _source_kernel_keys(source), and _filter_static_autotuners(bundle, source, bound_keys) (deferring AST name collection until an unbound key is encountered), and uses _filter_static_autotuners in both InductorSelections.register and relocate_inductor. Updates relocate_inductor so that both target == original (when freeze_tuning=True) and target != original validate and filter bundle.static_autotuners before _freeze_tuning_winners and before writing graph or mutating any CachingAutotuner. Entries with cache_key in bound_keys are retained; entries absent from bound_keys raise ValueError("compiled forward has unbound static Inductor kernels") when entry_kernel.kernel_name is in _referenced_kernel_names(source), and are removed from the bundle without mutating their device metadata or failing winner freezing when unreferenced (matching what InductorSelections.freeze produces on every rank). Updates InductorSelections.register to collect discovered (identity, tuner) pairs during AST traversal, validate every bundle.static_autotuners entry through _filter_static_autotuners before mutating state, and only then register each distinct tuner instance (including multiple globals sharing one cache_key), install an existing winner on each newly registered instance, and record self.forwards.
  • tests/preparation/test_inductor_prepared_winners.py: Adds CPU regression tests covering serialized peer-rank unreferenced-candidate pruning, exact-identifier prefix-collision handling across compiler (target == original, freeze_tuning=True) and peer (target != original, freeze_tuning in [False, True]) ranks, pre-mutation ValueError rejection in relocate_inductor (across both compiler and peer ranks) and InductorSelections.register, aliased async_compile.triton literal kernel names with a trailing same-key unused snapshot, and multi-global shared-key tuner preservation.

Claimed Result

On 0a8c20f4 CPU fixtures, relocate_inductor removes unreferenced epilogue candidates (including unresolved candidates under freeze_tuning=True on both compiler and peer ranks), InductorSelections.register ignores unreferenced candidates while preserving distinct tuners sharing a source key, and both fail closed with ValueError on referenced unbound kernels (including when shadowed by a later unused snapshot with the same key) without mutating graph, self.instances, or sibling autotuners. Separately, on 4x RTX PRO 6000 Blackwell (sm_120, TP4) using a locally patched checkout of Flare v0.4.4 (99339606), skipping unreferenced static_autotuners entries in relocate_inductor unblocked qwen38 TP4 preparation through native core export and flare run health startup across all four ranks; with both production files restored to 0a8c20f4 and the new tests retained, the serialized peer-load test raised KeyError. This changes Python preparation orchestration and its CPU tests only: InductorSelections.register on every rank and in single-device ForwardCache._warm, and relocate_inductor on every compiled-forward load that relocates (target != original) or freezes winners (a frozen artifact or triton.autotune_at_compile_time). It does not modify CUDA, PTX, CuTe DSL, Triton kernels, fusion, stream overlap, prepared core formats, or runtime ABIs.

Supporting Evidence and Limitations

  • Targeted CPU unit tests (Python 3.12, torch==2.14.1+cu132, triton==3.8.0 on 0a8c20f4):
    CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q \
      tests/preparation/test_inductor_prepared_winners.py \
      tests/preparation/test_aot_guards.py \
      tests/preparation/test_inductor_workspace_lifetimes.py
    32 passed in 4.63s (27 passed in test_inductor_prepared_winners.py, adding 9 test cases across 5 functions: test_load_inductor_relocation_drops_unreferenced_epilogue_candidates, test_relocate_inductor_skips_prefix_colliding_unreferenced_candidate_in_memory[(0, True), (1, False), (1, True)], test_relocate_inductor_rejects_referenced_unbound_kernel_without_partial_mutation[(0, True), (2, False), (2, True)], test_register_and_relocate_reject_aliased_triton_literal_without_partial_mutation, and test_register_preserves_distinct_tuners_sharing_source_key).
  • Full tests/preparation CPU suite (CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparation in the same 0a8c20f4 environment): Unmodified 0a8c20f4 yielded 1,148 passed, 74 skipped, 2 failed; this change yielded 1,157 passed, 74 skipped, 2 failed (+9 added cases). Both runs hit the same two unrelated failures (test_inductor_template_mutations.py::test_external_bmm_replacement_retains_input_mutation_dependency[clean] did not raise InductorError, and test_runtime_triton.py::test_replaces_clean_architecture_probe_and_preserves_patched_key saw platform.architecture() omit 'ELF' under uv-managed Python); neither test touches device_binding.py or inductor_tuning.py.
  • Revert check: Reverting ignition/preparation/device_binding.py and ignition/preparation/inductor_tuning.py causes all 8 behavior-change test cases in test_inductor_prepared_winners.py to fail (8 failed, 19 passed in 2.69s: KeyError on the serialized drop test, false-positive ValueError in register on all three prefix-collision cases, KeyError on peer freeze_tuning=False rejection, premature pending coordinate-descent tuning failure before binding validation on both (0, True) and (2, True) rejection cases, and DID NOT RAISE ValueError on register when the trailing unused same-key snapshot shadowed 'kernel_x'; test_register_preserves_distinct_tuners_sharing_source_key passes with and without the source change, confirming preservation of existing multi-global registration). All 27 tests in test_inductor_prepared_winners.py pass with the change.
  • Hardware reproduction provenance (4x RTX PRO 6000 Blackwell, sm_120, TP4, Flare v0.4.4 99339606, local-inference-lab/Qwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QAD dc5b8ab2 with the qwen38 recipe): On unmodified 99339606, qwen38 TP4 preparation failed during Load and warm compiled forwards with no error on rank 0 and KeyError inside relocate_inductor on ranks 1..3 for the forward named speculative16x5. On a locally patched checkout of 99339606 with an uncommitted guard in relocate_inductor that skipped static_autotuners entries absent from kernel_keys when entry.kernel_name was not a substring of graph.source_code, qwen38 TP4 preparation completed Load and warm compiled forwards, CUDA graph capture, native core export, and flare run health startup across all four ranks. The TP4 run exercised the substring guard. CPU tests exercised the submitted AST matcher against prefix collisions and aliased kernel names, aligned InductorSelections.register, and validated before freezing or mutation on 0a8c20f4.
  • Limitations: No GPU preparation was run on 0a8c20f4 with this exact submitted diff, and standalone CUDA unit tests (tests/preparation/*_cuda.py) were not run, including on the 4x RTX PRO 6000 host.

Authored by Gemini 4 Carbon and Gemini 4 Neon (docs/design-review.md principle 14).

Discord: jcartu

…ate_inductor

Tensor-parallel preparation aborts with `KeyError` on relocating ranks when a compiled forward's Triton bundle holds a static autotuner that the generated Python module never defines. During multi-rank preparation (`ForwardCache._prepare_ranks` in `ignition/preparation/aot.py`), `self._load` deserializes compiled forwards through `aot._load_inductor` with `frozen` false (the artifact's `_tuning_frozen` before `InductorSelections.freeze`), which invokes `relocate_inductor` (`ignition/preparation/device_binding.py`) before `InductorSelections.freeze` prunes `bundle.static_autotuners`. On the compiler rank (`target == original`) with `freeze_tuning=False`, `relocate_inductor` returns early without inspecting `static_autotuners`, and `InductorSelections.register` (`ignition/preparation/inductor_tuning.py`) ignores unreferenced `static_autotuners` entries left behind by PyTorch Inductor epilogue-fusion benchmarking (`entry.kernel_name` absent from the generated Python module). On peer tensor-parallel ranks (`target != original`) during the unfrozen load, `relocate_inductor` previously assigned `graph.source_code`, `graph.cache_key`, and `graph.device_idxs` before its loop and indexed `kernel_keys[entry_kernel.cache_key]` across every entry in `bundle.static_autotuners`. Because `_device_source` populates `kernel_keys` only from `async_compile.triton` calls present in `graph.source_code`, on an unfrozen peer load a bundled candidate whose cache key was absent from `kernel_keys` raised `KeyError`. Compiler-rank registration accepted the candidate in the TP4 reproduction, but its substring check could reject unused candidates with prefix-colliding names. When `freeze_tuning=True` (`ForwardCache._load` sets it from the `triton.autotune_at_compile_time` option), `_freeze_tuning_winners` also ran before checking bindings on both compiler and peer ranks, so an unresolved unreferenced candidate or referenced unbound kernel could fail winner freezing before missing bindings were diagnosed. In addition, `InductorSelections.register` previously mutated `self.instances` and called `_install` before checking unbound entries, collapsed duplicate unbound `cache_key` snapshots before checking names, and checked `entry.kernel_name in graph.source_code` by substring rather than exact identifier, which false-matches a prefix candidate such as `triton_tem_fused_1` when `triton_tem_fused_10` is bound (reproduced in CPU unit tests).

Dropping unreferenced `static_autotuners` entries during relocation and winner freezing is sound because any entry whose cache key has no `async_compile.triton` definition cannot be launched by the generated module, every launch in generated Inductor code names its kernel via a module-global identifier or `async_compile.triton` call string, and `InductorSelections.freeze` discards unreferenced entries on every rank anyway. This commit aligns unreferenced-candidate handling and pre-mutation validation across `ignition/preparation/device_binding.py` and `ignition/preparation/inductor_tuning.py`:
- Adds `_referenced_kernel_names(source)` (collecting AST `Name` identifiers and `async_compile.triton` string kernel names), `_source_kernel_keys(source)`, and `_filter_static_autotuners(bundle, source, bound_keys)` (deferring AST name collection until an unbound key is encountered) in `device_binding.py`, and uses `_filter_static_autotuners` in both `InductorSelections.register` and `relocate_inductor`.
- Updates `relocate_inductor` so that both `target == original` (when `freeze_tuning=True`) and `target != original` validate and filter `bundle.static_autotuners` before `_freeze_tuning_winners` and before writing `graph` or mutating any `CachingAutotuner`. Entries with `cache_key` in `bound_keys` are retained; entries absent from `bound_keys` raise `ValueError("compiled forward has unbound static Inductor kernels")` when `entry_kernel.kernel_name` is in `_referenced_kernel_names(source)`, and are removed from the bundle without mutating their device metadata or failing winner freezing when unreferenced (matching what `InductorSelections.freeze` produces on every rank).
- Updates `InductorSelections.register` to collect discovered `(identity, tuner)` pairs during AST traversal, validate every `bundle.static_autotuners` entry through `_filter_static_autotuners` before mutating state, and only then register each distinct tuner instance (including multiple globals sharing one `cache_key`), install an existing winner on each newly registered instance, and record `self.forwards`.
- Adds CPU regression tests in `tests/preparation/test_inductor_prepared_winners.py` covering serialized peer-rank unreferenced-candidate pruning, exact-identifier prefix-collision handling across compiler (`target == original, freeze_tuning=True`) and peer (`target != original, freeze_tuning in [False, True]`) ranks, pre-mutation `ValueError` rejection in `relocate_inductor` (across both compiler and peer ranks) and `InductorSelections.register`, aliased `async_compile.triton` literal kernel names with a trailing same-key unused snapshot, and multi-global shared-key tuner preservation.

On `0a8c20f4` CPU fixtures, `relocate_inductor` removes unreferenced epilogue candidates (including unresolved candidates under `freeze_tuning=True` on both compiler and peer ranks), `InductorSelections.register` ignores unreferenced candidates while preserving distinct tuners sharing a source key, and both fail closed with `ValueError` on referenced unbound kernels (including when shadowed by a later unused snapshot with the same key) without mutating `graph`, `self.instances`, or sibling autotuners. Separately, on 4x RTX PRO 6000 Blackwell (`sm_120`, TP4) using a locally patched checkout of `Flare v0.4.4` (`99339606`), skipping unreferenced `static_autotuners` entries in `relocate_inductor` unblocked `qwen38` TP4 preparation through native core export and `flare run` health startup across all four ranks; with both production files restored to `0a8c20f4` and the new tests retained, the serialized peer-load test raised `KeyError`. This changes Python preparation orchestration and its CPU tests only: `InductorSelections.register` on every rank and in single-device `ForwardCache._warm`, and `relocate_inductor` on every compiled-forward load that relocates (`target != original`) or freezes winners (a frozen artifact or `triton.autotune_at_compile_time`). It does not modify CUDA, PTX, CuTe DSL, Triton kernels, fusion, stream overlap, prepared core formats, or runtime ABIs.

Validation and limitations:
- Targeted CPU unit tests (`Python 3.12`, `torch==2.14.1+cu132`, `triton==3.8.0` on `0a8c20f4`): `CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparation/test_inductor_prepared_winners.py tests/preparation/test_aot_guards.py tests/preparation/test_inductor_workspace_lifetimes.py` passed (`32 passed` in `4.63s`; `27 passed` in `test_inductor_prepared_winners.py`, adding 9 test cases across 5 functions: `test_load_inductor_relocation_drops_unreferenced_epilogue_candidates`, `test_relocate_inductor_skips_prefix_colliding_unreferenced_candidate_in_memory[(0, True), (1, False), (1, True)]`, `test_relocate_inductor_rejects_referenced_unbound_kernel_without_partial_mutation[(0, True), (2, False), (2, True)]`, `test_register_and_relocate_reject_aliased_triton_literal_without_partial_mutation`, and `test_register_preserves_distinct_tuners_sharing_source_key`).
- Full `tests/preparation` CPU suite (`CUDA_VISIBLE_DEVICES="" .venv/bin/python -m pytest -q tests/preparation` in the same `0a8c20f4` environment): unmodified `0a8c20f4` reported `1,148 passed, 74 skipped, 2 failed`, and this change reported `1,157 passed, 74 skipped, 2 failed` (`+9` added cases). Both runs hit the same two unrelated failures (`test_inductor_template_mutations.py::test_external_bmm_replacement_retains_input_mutation_dependency[clean]` did not raise `InductorError`, and `test_runtime_triton.py::test_replaces_clean_architecture_probe_and_preserves_patched_key` saw `platform.architecture()` omit `'ELF'` under `uv`-managed Python); neither test touches `device_binding.py` or `inductor_tuning.py`.
- Revert check: reverting `ignition/preparation/device_binding.py` and `ignition/preparation/inductor_tuning.py` causes all 8 behavior-change test cases in `test_inductor_prepared_winners.py` to fail (`8 failed, 19 passed` in `2.69s`: `KeyError` on the serialized drop test, false-positive `ValueError` in `register` on all three prefix-collision cases, `KeyError` on peer `freeze_tuning=False` rejection, premature `pending coordinate-descent tuning` failure before binding validation on both `(0, True)` and `(2, True)` rejection cases, and `DID NOT RAISE ValueError` on `register` when the trailing unused same-key snapshot shadowed `'kernel_x'`; `test_register_preserves_distinct_tuners_sharing_source_key` passes with and without the source change, confirming preservation of existing multi-global registration). All `27` tests in `test_inductor_prepared_winners.py` pass with the change.
- Hardware reproduction provenance (`4x RTX PRO 6000 Blackwell`, `sm_120`, TP4, `Flare v0.4.4` `99339606`, `local-inference-lab/Qwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QAD` `dc5b8ab2` with the `qwen38` recipe): on unmodified `99339606`, `qwen38` TP4 preparation failed during `Load and warm compiled forwards` with no error on rank `0` and `KeyError` inside `relocate_inductor` on ranks `1..3` for the forward named `speculative16x5`. On a locally patched checkout of `99339606` with an uncommitted guard in `relocate_inductor` that skipped `static_autotuners` entries absent from `kernel_keys` when `entry.kernel_name` was not a substring of `graph.source_code`, `qwen38` TP4 preparation completed `Load and warm compiled forwards`, CUDA graph capture, native core export, and `flare run` health startup across all four ranks. The TP4 run exercised the substring guard. CPU tests exercised the submitted AST matcher against prefix collisions and aliased kernel names, aligned `InductorSelections.register`, and validated before freezing or mutation on `0a8c20f4`.
- Limitations: no GPU preparation was run on `0a8c20f4` with this exact submitted diff, and standalone CUDA unit tests (`tests/preparation/*_cuda.py`) were not run, including on the 4x RTX PRO 6000 host.

Design-Signed-Off-By: Gemini 4 Neon; design-review=2e5b
Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 642.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 30, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The relocation fix is structurally sound and has no blockers, but the submitted AST implementation has no green CI on head 5f6e6a6 and no GPU execution on this exact diff, and it adds an avoidable redundant AST walk on the frozen same-device reload path. Fix the evidence gap and collapse the duplicate helper to get this mergeable.

  • Blockers: 0 · Should fix: 2 · Subtract/Simplify: 2 · Nits: 3
Walkthrough
  • ignition/preparation/device_binding.py:92-130: Adds _referenced_kernel_names (AST Name identifiers plus async_compile.triton first string arg), _source_kernel_keys (CompiledTritonKernels.key per async_compile.triton kernel source), and _filter_static_autotuners (keeps bound keys, lazily resolves referenced names for unbound keys, drops unreferenced entries, raises ValueError("compiled forward has unbound static Inductor kernels") on referenced unbound entries).
  • ignition/preparation/device_binding.py:182-211: Restructures relocate_inductor to validate and filter bundle.static_autotuners before _freeze_tuning_winners and before mutating graph.source_code, graph.cache_key, graph.device_idxs, or per-kernel device metadata on both the frozen same-device (not relocate) and cross-device (relocate) paths, eliminating the kernel_keys[entry_kernel.cache_key] KeyError at :208.
  • ignition/preparation/inductor_tuning.py:18, 146, 165-175: Replaces #185's substring check (entries[key].kernel_name in graph.source_code) with _filter_static_autotuners, buffers (identity, tuner) pairs in discovered so validation completes before mutating self.instances or calling _install, and preserves multi-global tuners sharing one cache_key.
  • tests/preparation/test_inductor_prepared_winners.py:317-664: Adds 5 CPU unit test functions (9 parametrized cases; 27 total in the file) covering peer-rank unreferenced-candidate pruning via aot._load_inductor, exact-identifier prefix-collision handling, pre-mutation rejection, aliased async_compile.triton literals with trailing same-key shadow snapshots, and multi-global shared-key registration.
Merge Risk: Medium · up to 5f6e6a6
  • Broad preparation reach: relocate_inductor (device_binding.py:167-211) runs on every compiled-forward load that relocates or freezes winners (aot._load_inductor at aot.py:58, from StorageBackend.deserialize_compile_artifacts at :545 and compilation._compile_module at compilation.py:302); InductorSelections.register (inductor_tuning.py:135-175) runs once per forward per rank (aot.py:1232, 1377).
  • Low runtime/concurrency blast radius: No locks, collectives, wire/core formats, or CUDA/Triton kernels are modified; ForwardCache._prepare_ranks (aot.py:1223-1238) catches per-forward load/register errors and unconditionally enters selections._check(failure), so peer-only ValueError rejections cannot hang multi-rank barriers.
  • Verification gap drives the Medium rating: Zero CI checks have run on 5f6e6a6 and zero GPU tests (including test_inductor_tuning_cuda.py:490-536, 553+) have exercised the submitted AST matcher.
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings
  • ✅ Security / malicious screen: No prompt injection, shell execution, credential handling, or unsafe deserialization introduced; PR metadata (Discord: jcartu, agent-authorship disclosure) is normal process content.
  • ✅ Charter & value fit: Fixes a real SM120 TP>1 preparation failure in shared ignition/preparation with no new flags, env vars, or model branches, and touches preparation orchestration only (permitted under docs/design-review.md:124-134).
  • ✅ Related / duplicate / conflict check: Additive to main (completes the TP>1 peer-rank gap left untested by merged #185 and fixes #185's substring matcher); no main commit since branch point touches the three files, and open PR #597 does not modify inductor_tuning.py:18 or register (only adds cuda_device_identity at :21-26 and edits warm).
  • ⚠️ Tests & verification evidence: No .github/workflows/python-cpu.yml (not opened) run exists on 5f6e6a6 (branch predates #624's CPU CI fix), tests/preparation/test_inductor_tuning_cuda.py was not run, and the TP4 GPU run cited in Claimed Result exercised a different uncommitted substring guard on non-repo commit 99339606.
Should fix (2)
  1. Verify the submitted diff and align Claimed Result with what actually ran (docs/design-review.md:106-115, 171-189, tests/preparation/test_inductor_tuning_cuda.py:490-536, 553+): Rebase onto current main (includes #624) so .github/workflows/python-cpu.yml runs green on the PR head instead of relying on self-reported local CPU runs with two baseline failures; run test_inductor_tuning_cuda.py on this exact diff (at minimum test_unreferenced_bundled_candidates_are_dropped_and_named_kernels_still_bind at :490-536, ideally the ≥2-rank torchrun test at :553+ or a TP>1 export check) and report the actual command and result; tighten Claimed Result to lead with what was verified on this diff and state upfront that the 99339606 TP4 run validated an earlier substring-guard prototype.
  2. Collapse the duplicate AST walk and avoid unconditional parsing/hashing when static_autotuners is empty (device_binding.py:92-130, 182-188): _source_kernel_keys (:105-114) duplicates _referenced_kernel_names's ast.walk(ast.parse(source)) (:92-102) with a single caller at :184; on every frozen same-device load the module is parsed and every kernel hashed even when bundle.static_autotuners is empty, and parsed a second time (:127) if an unbound entry is hit. Merge into _source_kernel_refs(source, *, include_keys=False) with optional bound_keys=None: return [] immediately when not bundle.static_autotuners, collect bound_keys and referenced_names in one pass when bound_keys is None, and preserve the lazy fast path (no parse/hash unless an unbound cache_key appears) when bound_keys is supplied (:192, inductor_tuning.py:168).
Subtract / Simplify (2)
  1. Delete the dead assignment at device_binding.py:196: retained = retained_bundle.static_autotuners is a no-op since _freeze_tuning_winners mutates bundle.static_autotuners[:] in place at :164 (keep replace(bundle, static_autotuners=retained) so bundle.static_autotuners stays untouched if _freeze_tuning_winners raises, matching InductorSelections.freeze at inductor_tuning.py:325).
  2. Factor repeated test scaffolding in test_inductor_prepared_winners.py:250-259, 348-356, 430-434, 444-449, 506-511, 564-568, 578-582, 640-654: Two small module-level helpers (_stored_graph(source_code, bundle), _generated_callable(graph, tuners)) remove ~50 lines of duplicated CompiledFxGraph.__new__ / runner.__code__ = compile(...) boilerplate while keeping the function-local torch imports.
Nits (3)
  1. Include kernel diagnostics in the ValueError (device_binding.py:129): Append entry_kernel.kernel_name and entry_kernel.cache_key (preserving the "compiled forward has unbound static Inductor kernels" prefix matched by test_inductor_tuning_cuda.py:535 and test_inductor_prepared_winners.py:515, 589, 598) so multi-rank logs are actionable without a debugger.
  2. Diagnostic script edge case (scripts/inspect_forward_kernels.py:85-98): For a corrupt frozen artifact with ordinal == 0 and a referenced unbound kernel, _load_inductor (:85) now raises ValueError before the try: block (:90), aborting a multi-artifact sweep instead of emitting JSON with registered: false; wrapping :85-94 in the existing try: preserves per-artifact reporting (do not add a drop-only bypass to relocate_inductor).
  3. Remove duplicate comment (inductor_tuning.py:166) and trim PR description inventory (AGENTS.md:116-121, 138-139): Line 166 repeats the rationale already documented at device_binding.py:118-119.
Dropped on verification
Blockers

None.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants